//
//  ZYMusicTool.m
//  HB
//
//  Created by 孙智慧 on 16/1/22.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "ZYMusicTool.h"

@implementation ZYMusicTool

//歌曲集合
static NSMutableArray *_musics;
//正在播放的歌曲
static ZYMusic *_playingMusic;

+ (NSArray *)musics
{
    return _musics;
}
+(void) clear
{
    [_musics removeAllObjects];
}
+(void) addMusics:(ZYMusic *)zyMusic
{
    if (_musics == nil) {
        _musics=[[NSMutableArray alloc] init];
    }
    [_musics addObject:zyMusic];
}

+ (ZYMusic *)playingMusic
{
    return _playingMusic;
}

+ (void)setPlayingMusic:(ZYMusic *)playingMusic
{
    if (playingMusic == nil  || playingMusic == _playingMusic) { //|| ![_musics containsObject:playingMusic]
        return;
    }
    _playingMusic = playingMusic;
}


+ (ZYMusic *)nextMusic
{
    int nextIndex = 0;
    if (_playingMusic) {
        int playingIndex = (int)[_musics indexOfObject:_playingMusic];
        nextIndex = playingIndex + 1;
        if (nextIndex >= _musics.count) {
            nextIndex = 0;
        }
    }
    return _musics[nextIndex];
}

+ (ZYMusic *)previousMusic
{
    int previousIndex = 0;
    if (_playingMusic) {
        int playingIndex = (int)[_musics indexOfObject:_playingMusic];
        previousIndex = playingIndex - 1;
        if (previousIndex < 0) {
            previousIndex = (int)_musics.count - 1;
        }
    }
    return _musics[previousIndex];
}
@end
